// AI配置类型
export interface AIConfig {
  provider: AIProvider;
  apiKey: string;
  model?: string;
  temperature?: number;
  maxTokens?: number;
  priority?: number; // 优先级，数字越小优先级越高
  enabled?: boolean; // 是否启用
  maxRetries?: number; // 最大重试次数
}

// 多AI模型配置
export interface MultiAIConfig {
  models: AIConfig[];
  autoSwitch: boolean; // 是否启用自动切换
  fallbackOnError: boolean; // 错误时是否回退到下一个模型
  fallbackOnQuotaExhausted: boolean; // 配额耗尽时是否回退到下一个模型
}

// 应用配置类型定义
export interface AppConfig {
  gitUsername: string;
  aiProvider: AIProvider;
  apiKeys: Record<AIProvider, string>;
  excludePatterns: string[];
  projects: ProjectConfig[];
  selectedProjectId?: string;
  customTemplate?: string;
  aiConfig?: AIConfig;
  multiAIConfig?: MultiAIConfig; // 多AI模型配置
  customPrompts?: {
    simple?: string;
    professional?: string;
  };
}

// 项目配置类型
export interface ProjectConfig {
  id: string;
  name: string;
  path: string;
  gitPath?: string;
  description?: string;
  addedAt: string;
}

// AI服务提供商类型
export type AIProvider = 'google' | 'deepseek' | 'tongyi' | 'doubao' | 'wenxin';

// 报告类型
export type ReportType = 'daily' | 'weekly' | 'custom';

// 项目类型
export interface Project {
  id: string;
  name: string;
  path: string;
  description?: string;
}

// 项目信息类型（与后端API对应）
export interface ProjectInfo {
  id: string;
  name: string;
  path: string;
  description?: string;
  lastAnalyzed?: string;
  totalCommits?: number;
  authors?: string[];
  createdAt?: string;
  updatedAt?: string;
  addedAt: string;
}

// 生成的报告类型
export interface GeneratedReport {
  id: string;
  type: ReportType;
  title: string;
  content: string;
  projectPath: string;
  author?: string;
  dateRange: {
    start: string;
    end: string;
  };
  stats: {
    totalCommits: number;
    totalFiles: number;
    totalAdditions: number;
    totalDeletions: number;
    authors: string[];
  };
  generatedAt: string;
  aiConfig?: AIConfig;
}

// Git提交类型
export interface GitCommit {
  hash: string;
  message: string;
  author: string;
  email?: string;
  date: Date;
}

// Git变更类型
export interface GitChange {
  file: string;
  type: 'added' | 'modified' | 'deleted';
  additions: number;
  deletions: number;
  diff: string;
  commit: {
    hash: string;
    message: string;
    author: string;
    date: Date;
  };
}

// 时间范围类型
export type TimeRange = 'daily' | 'weekly' | 'monthly' | 'custom';

// 报告类型
export interface Report {
  id: string;
  projectName: string;
  timeRange: string;
  startDate: string;
  endDate: string;
  content: string;
  createdAt: string;
}

// API响应类型
export interface ApiResponse<T = any> {
  success: boolean;
  data?: T;
  error?: string;
}

// 组件Props类型
export interface ProjectListProps {
  projects: ProjectConfig[];
  onAddProject: (projectPath: string, projectName: string) => Promise<boolean>;
  onRemoveProject: (projectId: string) => Promise<void>;
  onSelectProject: (project: ProjectConfig) => void;
}

export interface ReportGeneratorProps {
  config: AppConfig;
  onMessage: (type: 'success' | 'error', text: string) => void;
  selectedProject?: ProjectConfig;
}

export interface ConfigFormProps {
  config: AppConfig;
  onConfigChange: (config: AppConfig) => void;
  onMessage: (type: 'success' | 'error', text: string) => void;
}

// 默认配置
export const defaultConfig: AppConfig = {
  gitUsername: '',
  aiProvider: 'google',
  apiKeys: {
    google: '',
    deepseek: '',
    tongyi: '',
    doubao: '',
    wenxin: ''
  },
  excludePatterns: [
    'node_modules/**',
    '.git/**',
    'dist/**',
    'build/**',
    '*.log',
    '.env*'
  ],
  projects: [],
  customTemplate: '',
  aiConfig: {
    provider: 'deepseek',
    apiKey: '',
    model: 'deepseek-chat',
    temperature: 0.7,
    maxTokens: 2000
  },
  multiAIConfig: {
    models: [
      {
        provider: 'tongyi',
        apiKey: '',
        model: 'qwen-max-2025-01-25',
        temperature: 0.7,
        maxTokens: 2000,
        priority: 1,
        enabled: true,
        maxRetries: 3
      },
      // {
      //   provider: 'deepseek',
      //   apiKey: '',
      //   model: 'deepseek-reasoner',
      //   temperature: 0.7,
      //   maxTokens: 2000,
      //   priority: 2,
      //   enabled: true,
      //   maxRetries: 3
      // },
      {
        provider: 'doubao',
        apiKey: '',
        model: 'doubao-seed-1-6-250615',
        temperature: 0.7,
        maxTokens: 2000,
        priority: 3,
        enabled: true,
        maxRetries: 3
      }
    ],
    autoSwitch: true,
    fallbackOnError: true,
    fallbackOnQuotaExhausted: true
  },
  customPrompts: {
    simple: '',
    professional: ''
  }
};